<?php include("../mvz-config/system/begin.php"); ?>
<?php include("../mvz-config/system/session_start.php"); ?>
<?php $msg="";if(isset($_SESSION['msg'])){$msg = $_SESSION['msg']; session_complete_destroy();} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<?php include("includes/head.php"); ?>
</head>
<body style="overflow: hidden;" >
	<form name="LoginForm" method="POST" action="login_check.php" onSubmit="return LoginFormValidate()">
		<div style="display: table; height: 96%; width:100%; #position: relative; overflow: hidden;">
			<div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; width:100%; ">
				<div style=" #position: relative; #top: -50%; text-align:center;">
					<div class="login_box">
						<div>
							<?php
								// Get DB Status
								
								$db_status = check_database_status(1);	// return $db_status
								//echo $db_status;die();
								if($db_status == 1)
								{
									// Setting last opened URL path if session is expired
									
									if(isset($_SESSION['url_referer'])){$referer = $_SESSION['url_referer'];}else{$referer="";}
									if($referer != "" || empty($referer))
									{
										$mystring = strtolower($referer);
										
										// Add Filter HTTP Referer here (separate by comma)
										$filter_referer = array
											(
												1=>"logout",
												2=>"process"
											);
										
										foreach($filter_referer as $fr => $fr_val)
										{
											$no = $fr; $findstring = "findme_".$no; $posstring = "pos_".$no; $$findstring = $fr_val; $$posstring = strpos($mystring, $$findstring);
										}
										
										for($x=1;$x<(count($filter_referer));$x++)
										{
											$posstring = "pos_".$x;
											
											if($posstring === false)
											{
												$http_referer = $referer;
											}
											else
											{
												$http_referer = "";
											}
										}
									}
									else
									{
										$http_referer = "";
									}
							?>
							<input name="http_referer" type="hidden" value="<?php echo $http_referer; ?>">
							<?php
									if(isset($msg))
									{
										if($msg != "" || !empty($msg) )
										{
											switch($msg)
											{	
												// Empty String Login
												case 'user':
													$error_msg = "Please input username";
													break;
												case 'pass':
													$error_msg = "Please input password";
													break;
												case 'userpass':
													$error_msg = "Please input username & password";
													break;
											
												// IP Punished
												case 'x':
													$error_msg = "Warning !!!<br />Maximum Login Limit reached<br />Please try Login again later";
													break;
												case 'blk':
													$error_msg = "Warning !!!<br />Your IP is blocked";
													break;
													
												// Session Fail
												case 'li':
													$error_msg = "Please Login";
													break;
												case 'exp':
													$error_msg = "Session expired<br />Please Relogin";
													break;
													
												// Login Validation Fail
												case 'ne':
													$error_msg = "Username is not found";
													break;
												case 'f':
													$error_msg = "Wrong Password";
													break;
												case 'b':
													$error_msg = "Username is banned";
													break;
												case 'e':
													$error_msg = "Can't Login Right Now";
													break;
												
												// Logout Success
												case 'lo':
													$error_msg = "Logout Successful";
													break;
												
												// Default
												default:
													$error_msg = "";
													break;
											}
							?>
							<br /><br />
							<div class="login_msg">
								<div><font style='color: #f00; font-weight: bold;'><?php echo $error_msg; ?></font></div>
								<div style="clear:both;"></div>
							</div>
							<br /><br />
							<?php
										}
									}
							?>
							
							<div>
								<br />
								<br />
								<a href="<?php echo getURLdomain(); ?>" target="_blank" >
								<?php
									$sql = "select filename from ms_file where stsrc = 'A' and filerole = 'logo' order by dateup desc, datein desc limit 0,1";
									$exe = mysql_query($sql) or die(mysql_error());
									$num = mysql_num_rows($exe);
									$row = mysql_fetch_array($exe);
									
									if($num > 0)
									{
								?>
										<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" border="0" style="max-width:300px; max-height:150px;" title="<?php echo getURLdomain(); ?>" />
								<?php
									}
									else
									{
								?>
										<img src="<?php echo PATH_LOGO; ?>" border="0" style="max-width:300px; max-height:150px;" title="oewjoiwefjoiwje" />
								<?php
									}
								?>
								</a>
							</div>
							
							<div>
								<br /><br />
								<span style="font-weight: bold;">USERNAME</span><br />
								<input name="username" type="text" class="login_field" size="20" maxlength="11" style="width: 310px; text-align:center;" >
								<br /><br />
								<span style="font-weight: bold;">PASSWORD</span><br />
								<input name="password" type="password" class="login_field" size="20" maxlength="10" style="width: 310px; text-align:center;" >
								<br /><br />
								<span><input type="reset" value="Reset" text="Reset" /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<span><input type="submit" value="Login" text="Login" /></span>
								<br /><br />
							</div>
							<?php 
								}
							?>
							<div>
								<div style="float:left; padding:10px;">
									<a href="http://www.google.com/intl/en/chrome/" target="_blank"><img src="<?php echo getURLdomain()."/source/global/img/icon/chrome-icon.png"; ?>" width="16" height="16" title="Chrome" /></a>
									<a href="http://www.mozilla.org/en-US/firefox/new/" target="_blank"><img src="<?php echo getURLdomain()."/source/global/img/icon/firefox-icon.png"; ?>" width="16" height="16" title="Mozilla Firefox" /></a>
								</div>
								<div style="float:right; padding:10px;">
									<a href="http://madebymvz.com/" title="MvZ">
										<img src="<?php echo PATH_FAVICON; ?>" style="max-width:24px; max-height:24px;" alt="MvZ" /> <?php echo CMS_ENGINE_VERSION; ?>
									</a>
								</div>
								<div class="clear"></div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
</body>
</html>
<?php include("../mvz-config/system/end.php"); ?>
<script language="javascript">
	document.LoginForm.username.focus();
</script>